﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace HZ.Supervise.Web.Common
{
    public partial class MaxforMonth : System.Web.UI.UserControl
    {
       
        public void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Banding();
            } 
        }

        public string Getvalue()
        {
            return DDLMonth.SelectedItem.Value;
        }
        public void Banding()
        {
            DDLMonth.Items.Clear();
            int nYear = System.DateTime.Now.Year;
            int nmonth = System.DateTime.Now.Month;
            int nmm = 0;
            for (int mm = nmonth; mm > 0; mm--)
            {
                ListItem itme = new ListItem();
                itme.Text = nYear.ToString() + "年" + GetFormatmonth(mm) + "月";
                itme.Value = nYear.ToString() + GetFormatmonth(mm);
                DDLMonth.Items.Add(itme);
                nmm = mm;
            }
            for (int mm = 12; mm > 12 - nmm; mm--)
            {
                ListItem itme = new ListItem();
                itme.Text = (nYear - 1).ToString() + "年" + GetFormatmonth(mm) + "月";
                itme.Value = (nYear-1).ToString() + GetFormatmonth(mm);
                DDLMonth.Items.Add(itme);
                nmm = mm;
            }
            DDLMonth.SelectedIndex = 0;
        }

        /// <summary>
        /// 格式化月份
        /// </summary>
        /// <param name="nmonth"></param>
        /// <returns></returns>
        private string GetFormatmonth(int nmonth)
        {
            if (nmonth.ToString().Length > 1)
            {
                return nmonth.ToString();
            }
            else
            {
                return "0" + nmonth.ToString();
            }
        }
    }
}